Skip to content

Conversation

@comandeo
Copy link
Contributor

@comandeo comandeo commented Nov 3, 2025

No description provided.

@comandeo-mongo comandeo-mongo marked this pull request as ready for review December 12, 2025 08:54
@comandeo-mongo comandeo-mongo requested a review from a team as a code owner December 12, 2025 08:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds OpenTelemetry tracing support to the MongoDB Ruby driver, enabling distributed tracing capabilities for MongoDB operations and commands following the OpenTelemetry semantic conventions for database instrumentation.

Key changes:

  • New tracing infrastructure with Mongo::Tracing::OpenTelemetry::Tracer, OperationTracer, and CommandTracer classes
  • Integration of tracing into client, collection, database, and session operations
  • Support for transaction span tracking and cursor context management
  • Environment variable configuration for enabling tracing and query text capture
  • Comprehensive test suite including unified spec tests for OpenTelemetry

Reviewed changes

Copilot reviewed 62 out of 62 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/mongo/tracing.rb Main tracing module with factory method for creating tracers
lib/mongo/tracing/open_telemetry/tracer.rb Core tracer implementation managing operation and command tracing
lib/mongo/tracing/open_telemetry/operation_tracer.rb Tracer for driver-level operations with span attribute management
lib/mongo/tracing/open_telemetry/command_tracer.rb Tracer for server commands with query text capture support
lib/mongo/client.rb Client integration for tracer initialization and configuration
lib/mongo/session.rb Transaction span lifecycle management
lib/mongo/operation/shared/executable.rb Command tracing integration in operation execution
lib/mongo/collection.rb Operation tracing for collection methods
lib/mongo/collection/view/*.rb Tracing integration for view operations
lib/mongo/index/view.rb Index operation tracing
spec/support/tracing.rb Mock tracing infrastructure for testing
spec/spec_tests/open_telemetry_spec.rb Unified spec test runner for OpenTelemetry
spec/spec_tests/data/open_telemetry/**/*.yml Comprehensive test specifications

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

end
end

gem 'opentelemetry-api'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? It looks like opentelemetry-sdk declares opentelemtry-api as a dependency (here)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thank you. Fixed.

#
# @return [ String | nil ] the collection name, or nil if not applicable.
def collection_name(message)
case message.documents.first.keys.first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be stable? Are we guaranteed that the first key will always be the name of the command? Though, honestly, I don't have any better ideas for how to extract the command name here...

Also, perhaps it would be clearer to use the #command_name method here, which has the same logic but also does #to_s.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not find a concrete statement that the first key is always the command name; however, this is so for all the documented command.

EXCLUDED_KEYS = %w[lsid $db $clusterTime signature].freeze

# Ellipsis for truncated query text.
ELLIPSES = '...'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Ellipsis" (with an 'i') is a single set of three dots, e.g. '...'

"Ellipses" (with an 'e') is the plural, referring to multiple sets of three dots. E.g. "I really like ellipses... I use them everywhere..."

Suggested change
ELLIPSES = '...'
ELLIPSIS = '...'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@comandeo-mongo comandeo-mongo requested a review from jamis December 18, 2025 08:01
@comandeo-mongo comandeo-mongo merged commit 5e64c1d into mongodb:master Dec 19, 2025
166 of 168 checks passed
@comandeo-mongo comandeo-mongo deleted the 3612-otel branch December 19, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants